package com.xin.jdbc;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class jdbcdemo {
    public static void main(String[] args) {
        Connection conn=null;
        Statement sta=null;
        try {
            java.sql.Driver driver = new com.mysql.jdbc.Driver();
            DriverManager.registerDriver(driver);
            String url="jdbc:mysql://127.0.0.1:3306/student_manage";
            String user="root";
            String password="856736";
            conn = DriverManager.getConnection(url,user,password);
            sta = conn.createStatement();
            String updata="update stu_information set age=19 where stu_id=2 ";
            int i = sta.executeUpdate(updata);
            if(i==1){
                System.out.println("执行成功");
            }else{
                System.out.println("执行失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            if(sta!=null) {
                try {
                    sta.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (conn!=null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
